import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const state = {
	tableData: [
		{
			id: 1,
			name: '电风扇',
			count: 100,
			weight: '100kg',
			category: '电器',
			date: '2020/1/1',
			note: '家用电器(HEA)主要指在家庭及类似从繁重、琐碎、费时的家务劳动中解放出来',
		},
		{
			id: 2,
			name: '冰箱',
			count: 110,
			weight: '122kg',
			category: '电器',
			date: '2020/1/1',
			note: '这是飞哥的快递哦',
		},
		{
			id: 3,
			name: '桌子',
			count: 4,
			weight: '100kg',
			category: '家具',
			date: '2020/1/1',
			note: '这是曾毛毛的快递',
		},
		{
			id: 4,
			name: '电风扇',
			count: 100,
			weight: '100kg',
			category: '电器',
			date: '2020/1/1',
			note: '家用电器(HEA)主要指在家庭及类似场所中使用的各种家用电器使人们从繁重、琐碎、费时的家务劳动中解放出来',
		},
		{
			id: 5,
			name: '电风扇',
			count: 100,
			weight: '100kg',
			category: '电器',
			date: '2020/1/1',
			note: '又称民用电器、日用电器。家用电器使人们从繁重、琐碎、费时的家务劳动中解放出来',
		},
		{
			id: 6,
			name: '电风扇',
			count: 100,
			weight: '100kg',
			category: '电器',
			date: '2020/1/1',
			note: '上古神器，务必轻拿轻放!',
		},
		{
			id: 7,
			name: '电风扇',
			count: 100,
			weight: '100kg',
			category: '电器',
			date: '2020/1/1',
			note: '上古神器，务必轻拿轻放!',
		},
		{
			id: 8,
			name: '电风扇',
			count: 100,
			weight: '100kg',
			category: '电器',
			date: '2020/1/1',
			note: '上古神器，务必轻拿轻放!',
		},
		{
			id: 9,
			name: '电风扇',
			count: 100,
			weight: '100kg',
			category: '电器',
			date: '2020/1/1',
			note: '上古神器，务必轻拿轻放!'},
		{
			id: 10,
			name: '电风扇',
			count: 100,
			weight: '100kg',
			category: '电器',
			date: '2020/1/1',
			note: '上古神器，务必轻拿轻放!'},
		{
			id: 11,
			name: '电风扇',
			count: 100,
			weight: '100kg',
			category: '电器',
			date: '2020/1/1',
			note: '上古神器，务必轻拿轻放!'},
		{
			id: 12,
			name: '电风扇',
			count: 100,
			weight: '100kg',
			category: '电器',
			date: '2020/1/1',
			note: '上古神器，务必轻拿轻放!'
			
		},
	],
	checkData:[
		{
			id: 1,
			name: '电风扇',
			count: 100,
			weight: '100kg',
			category: '电器',
			date: '2020/1/1',
			note: '家用电器(HEA)主要指在家庭及类似从繁重、琐碎、费时的家务劳动中解放出来',
		},
		{
			id: 1,
			name: '冰箱',
			count: 100,
			weight: '100kg',
			category: '电器',
			date: '2020/1/1',
			note: '家用电器(HEA)主要指在家庭及类似从繁重、琐碎、费时的家务劳动中解放出来',
		},
		{
			id: 1,
			name: '电风扇',
			count: 100,
			weight: '100kg',
			category: '电器',
			date: '2020/1/1',
			note: '家用电器(HEA)主要指在家庭及类似从繁重、琐碎、费时的家务劳动中解放出来',
		},
		{
			id: 1,
			name: '电风扇',
			count: 100,
			weight: '100kg',
			category: '电器',
			date: '2020/1/1',
			note: '家用电器(HEA)主要指在家庭及类似从繁重、琐碎、费时的家务劳动中解放出来',
		},
		{
			id: 1,
			name: '电风扇',
			count: 100,
			weight: '100kg',
			category: '电器',
			date: '2020/1/1',
			note: '家用电器(HEA)主要指在家庭及类似从繁重、琐碎、费时的家务劳动中解放出来',
		},
		{
			id: 1,
			name: '电风扇',
			count: 100,
			weight: '100kg',
			category: '电器',
			date: '2020/1/1',
			note: '家用电器(HEA)主要指在家庭及类似从繁重、琐碎、费时的家务劳动中解放出来',
		},
	]
}
const actions = {
}
const mutations = {
	// 删除货物信息
	deleteGoodsInfo(store,payload) {
		Vue.delete(store.tableData,payload.index)
		// store.tableData[payload.index] = {}
		// payload.rows.splice(payload.index, 1);
	},
	deleteCheckGoods(store,payload) {
		// 删除审核货物
		Vue.delete(store.checkData,payload.index)
	},
	changeGoodsInfo(store,payload) {
		// 修改货物信息
		Vue.set(store.tableData, payload.curIndex, payload.goods)
	},
	pushGoods(store,payload) {
		// 审核货物入库
		store.tableData.push(...store.checkData.splice(payload.index,1))
	}
	
}
const getters = {
	showDataByPage(state){
		return function (data){
			let end = parseInt(data.pageSize)*parseInt(data.curPage)
			let start = end - parseInt(data.pageSize)
			let pageData = []
			for(let i = start ; i< end ; i++){
				if(state.tableData[i]){
					pageData.push(state.tableData[i])
				}
			}
			return pageData
		}
	}
}
const modules = {}


const store = new Vuex.Store({
	actions,
	mutations,
	getters,
	state,
	modules
})

export default store

